home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / Source / DBL Pascal Library / Levenshtein ƒ / Levenshtein test.p < prev    next >
Text File  |  1992-05-06  |  1KB  |  51 lines

  1. program Levenshtein_test;
  2.  
  3.     uses
  4.         Levenshtein;
  5.  
  6.     procedure PrepareTextWindow;
  7.         const
  8.             MaxVSize = 300;
  9.             MaxHSize = 500;
  10.         var
  11.             aRect: Rect;
  12.     begin
  13.         aRect := screenBits.bounds;
  14.         InsetRect(aRect, 40, 40);
  15.         with aRect do
  16.             begin
  17.                 if bottom - top > MaxVSize then
  18.                     bottom := top + MaxVSize;
  19.                 if right - left > MaxHSize then
  20.                     right := left + MaxHSize;
  21.             end;
  22.         SetTextRect(aRect);
  23.         ShowText;
  24.     end;
  25.  
  26.     var
  27.         matchCost, insertCost, deleteCost, substituteCost: Integer;
  28.         aString, bString: Str255;
  29.         distance, moves, i: Integer;
  30.         opsH: LevOpsHdl;
  31.  
  32. begin
  33.     PrepareTextWindow;
  34.     writeln('Enter costs for match, insert, delete, substitute:');
  35.     readln(matchCost, insertCost, deleteCost, substituteCost);
  36.     InitLevDist(matchCost, insertCost, deleteCost, substituteCost);
  37.     opsH := LevOpsHdl(NewHandle(0));
  38.     repeat
  39.         writeln('Enter two strings');
  40.         readln(aString);
  41.         readln(bString);
  42.         distance := LevDist(aString, bString, opsH, moves);
  43.         writeln('Levenshtein distance = ', distance : 1);
  44.         HLock(Handle(opsH));
  45.         for i := 1 to moves do
  46.             with opsH^^[i] do
  47.                 writeln(i : 1, ' (', iA : 1, ',', iB : 1, ') ', op);
  48.         HUnlock(Handle(opsH));
  49.     until (aString = '') and (bString = '');
  50.  
  51. end.